package com.zzh.takeoutapp.adapter;

import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RatingBar;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zzh.takeoutapp.R;
import com.zzh.takeoutapp.entity.CollectOrderEntity;
import com.zzh.takeoutapp.entity.FoodBean;
import com.zzh.takeoutapp.entity.HomeShopEntity;
import com.zzh.takeoutapp.utils.ImageManager;

import java.util.List;

import butterknife.Bind;

/**
 * Created by Administrator on 2018/7/30.
 */

public class CollectOrderAdapter extends BaseQuickAdapter<CollectOrderEntity, BaseViewHolder> {
    public static final int FIRST_STICKY_VIEW = 1;
    public static final int HAS_STICKY_VIEW = 2;
    public static final int NONE_STICKY_VIEW = 3;
    private List<CollectOrderEntity> flist;

    public CollectOrderAdapter(@Nullable List<CollectOrderEntity> data) {
        super(R.layout.item_home_orders, data);
        this.flist = data;
    }

    @Override
    protected void convert(BaseViewHolder helper, CollectOrderEntity itemsBean) {
        ImageManager.loadUrlImage(mContext, itemsBean.getLogo(), (ImageView) helper.getView(R.id.draw_goods));
        helper.setText(R.id.title, itemsBean.getTitle());
        helper.setText(R.id.tv_avg_score, String.valueOf(itemsBean.getScore()));
        helper.setText(R.id.tv_orders, "月售  " + String.valueOf(itemsBean.getOrders()));
        helper.setText(R.id.tv_juli_label, "30分钟 | " + String.valueOf(itemsBean.getJuli_label()));
        helper.setText(R.id.min_amount, "起送  ￥" + String.valueOf(itemsBean.getMin_amount()) + "  |  " +
                "配送  ￥" + String.valueOf(itemsBean.getFreight()) + "  |  " +
                "人均  ￥" + String.valueOf(itemsBean.getFreight()));
        helper.setRating(R.id.rb, Float.parseFloat(String.valueOf(itemsBean.getScore())));
        helper.setText(R.id.title, itemsBean.getTitle());
        helper.setText(R.id.title, itemsBean.getTitle());
        helper.setText(R.id.title, itemsBean.getTitle());
        helper.setText(R.id.title, itemsBean.getTitle());
        helper.getView(R.id.stick_header).setVisibility(View.VISIBLE);
        if (helper.getAdapterPosition() == 0) {
            helper.setVisible(R.id.stick_header, true)
                    .setText(R.id.tv_header, itemsBean.getType())
                    .setTag(R.id.food_main, FIRST_STICKY_VIEW);
        } else {
            if (!TextUtils.equals(itemsBean.getType(), flist.get(helper.getAdapterPosition() - 1).getType())) {
                helper.setVisible(R.id.stick_header, true)
                        .setText(R.id.tv_header, itemsBean.getType())
                        .setTag(R.id.food_main, HAS_STICKY_VIEW);
            } else {
                helper.setVisible(R.id.stick_header, false)
                        .setTag(R.id.food_main, NONE_STICKY_VIEW);
            }
        }
        helper.getConvertView().setContentDescription(itemsBean.getType());
    }
}
